package com.coreservlets.jsf.ss07;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;

import com.coreservlets.jsf.ss06.BankingBean;
import com.coreservlets.jsf.ss06.ICustomerLookupService;

@ManagedBean
public class BankingBean3 extends BankingBean 
{
	@ManagedProperty(value="#{customerSimpleMap2}")
	private ICustomerLookupService service;
	public void setService( ICustomerLookupService service )
	{
		this.service = service;
	}
	
	
	@Override
	public String showBalance()
	{
		if(!getPassword().equals( "secret"))
		{
			return( "wrong-password3");
		}
		
		setCustomer( service.findCustomer( getCustomerId() ) );
		
		if( getCustomer() == null )
		{
			return( "unkown-customer3" );
		}
		else if( getCustomer().getBalance() < 0 )
		{
			return( "negative-balance3");
		}
		else if( getCustomer().getBalance() < 10000 )
		{
			return( "normal-balance3");
		}
		else
		{
			return( "high-balance3");
		}
			
	}
}
																																																																																																								